import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    component: () => import('@/views/layout/Layout.vue'),
    children: [
      {
        path: '',
        redirect: '/home'
      },
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/Home.vue')
      },
      {
        path: 'search',
        name: 'Search',
        component: () => import('@/views/search/Search.vue')
      },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/user/User.vue'),
        children: [
          {
            path: 'edit',
            name: 'EditProfile',
            component: () => import('@/views/user/EditProfile.vue')
          }
        ]
      },
      {
        path: 'downloadclient',
        name: 'DownloadClient',
        component: () => import('@/views/music/DownloadClient.vue')
      },
      {
        path: 'upload',
        name: 'Upload',
        component: () => import('@/views/music/Upload.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/auth/Login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/auth/Register.vue')
  },
  {
    path: '/forgot-password',
    name: 'ForgotPassword',
    component: () => import('@/views/auth/ForgotPassword.vue')
  },
  // 匹配所有路径，重定向到首页
  {
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router 